const loginUtil = require('../../utils/login.js')
//获取应用实例
var app = getApp()
Page({
  data: {
    scale: 18,
    latitude: 0,
    longitude: 0,
    controls:[],
    hasLogin:true
  },
  // 页面加载
  onLoad: function(options) {
    // 2.获取并设置当前位置经纬度
    wx.getLocation({
      type: "gcj02",
      success: (res) => {
        this.setData({
          longitude: res.longitude,
          latitude: res.latitude
        })
      }
    });

    // 1.创建地图上下文，移动当前位置到地图中心
    this.mapCtx = wx.createMapContext("ofoMap");
    this.movetoPosition();
  },

  refreshUI:function(){
    loginUtil.simpleLogin((hasLogin) => {
      this.setData({
        hasLogin:hasLogin
      })
    });
   
  },

  // 页面显示
  onShow: function() {
    this.refreshUI();
  },


  // 定位函数，移动位置到地图中心
  movetoPosition: function() {
    this.mapCtx.moveToLocation();
  },

  login:function(){
    wx.navigateTo({
      url: '/pages/login/Login',
    })
  },

  goUserCenter:function(){
    wx.navigateTo({
      url: '/pages/me/me',
    })
  },

// 加油
  jiayou:function(){
    wx.navigateTo({
      url: '/pages/jiayou/jiayou-list',
    })
  },

  godev:function(e){
    if (this.data.hasLogin){
      wx.navigateTo({
        url: '/pages/me/mybook-list',
      });
    }
    else{
      wx.navigateTo({
        url: '/pages/login/Login',
      });
    }
    
    return;
    wx.navigateTo({
      url: '/pages/dev/develop-page?title=' + e.currentTarget.dataset.title,
    })
  }
})